<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="出单日期">
              <a-range-picker v-model="timeData" @change="timeChange" format="YYYY-MM-DD HH:mm:ss" :show-time="true" style="width: 100%;" />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="运营专员">
              <j-search-select-user v-model="queryParam.createBy" placeholder="请输入并选择运营专员"></j-search-select-user>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <!-- <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a> -->
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange"
        :customRow="selectRowData">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;" :preview="0"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>
      </a-table>
    </div>
  </a-card>
</template>

<script>
  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import moment from 'moment'
  export default {
    name: 'ProductLibraryBillForm',
    mixins:[JeecgListMixin, mixinDevice],
    components: {},
    data () {
      return {
        description: '产品库-标签管理页面',
        model: {},
        disableMixinCreated: true,
        timeData: [],
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'平台编号',
            align:"center",
            dataIndex: 'msku'
          },
          {
            title:'平台订单号',
            align:"center",
            dataIndex: 'skuId'
          },
          {
            title:'平台',
            align:"center",
            dataIndex: 'platformName'
          },
          {
            title:'产品名称',
            align:"center",
            dataIndex: 'productName'
          },
          {
            title:'出单时间',
            align:"center",
            dataIndex: 'purchaseDate'
          },
          {
            title:'出单量',
            align:"center",
            dataIndex: 'quantity'
          },
          {
            title:'运营专员',
            align:"center",
            dataIndex: 'createBy'
          }
        ],
        url: {
          list: "/hzkj-oms/oms/product/statistics/detail/list",          
        },
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
      //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
      this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
        if(this.model.id){
          this.queryParam.skuId = this.model.skuId;
          this.queryParam.queryDimension = this.model.queryDimension;
          this.loadData();
        }
      },
      initDictConfig(){
      },
      selectRowData(record,index){
        const that = this
        return {
          on:{
            dblclick:() => {
              // this.handleDetail(record)
            }
          }
        }
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'name',text:'标签名称',dictCode:''})
        fieldList.push({type:'int',value:'type',text:'标签类型',dictCode:'product_tag_type'})
        fieldList.push({type:'string',value:'createBy',text:'创建人',dictCode:''})
        this.superFieldList = fieldList
      },
      timeChange(time1, time2){
        this.queryParam.startTime = time2 && time2[0];
        this.queryParam.endTime = time2 && time2[1];
      },
      searchReset(){
        this.timeData = [];
        this.queryParam = {
          skuId: this.model.skuId,
          queryDimension: this.model.queryDimension
        }
        this.loadData(1);
      },
      searchQuery(){
        this.queryParam = {
          ...this.queryParam,
          queryDimension: this.queryParam.startTime ? '' : this.model.queryDimension
        }
        this.loadData(1);
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>